﻿@{
    ViewBag.Title = "检验、检查报告表单页";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<style>
    /*#dc {
        float: right;
        background-color: #e9f6fe !important;
        height: 12px;
        width: 130px;
        padding: 10px;
        color: black;
    }*/

    .noselected {
        float: left;
        background-color: #e9f6fe !important;
        height: 12px;
        width: 130px;
        padding: 10px;
        color: black;
        border: solid 1px black;
    }

    .selected {
        float: left;
        background-color: #ffffff;
        height: 12px;
        width: 130px;
        padding: 10px;
        color: #00a0ea;
        border: solid 1px #00a0ea;
    }

    .hide {
        display: none;
    }
</style>
<form id="formPatSer" style="margin:2px;margin-top:10px;">
	<div style="background-color: #e9f6fe !important;height:36px;width:100%">
		<ul class="nav nav-tabs navb-bg" id="myTab" style="position:fixed;top:0;z-index:100009;width:99%">
			<li role="presentation"><a href="#jy" role="tab" data-toggle="tab">检验</a></li>
			<li role="presentation"><a href="#jc" role="tab" data-toggle="tab">检查</a></li>
		</ul>
			@*<input id="jy" name="jy" type="button" value="检验" class="selected" />
			<input id="jc" name="jc" type="button" value="检查" class="noselected" />*@
	</div>
    <div class="gridPanel" id="jyjgmx">
        <div>
            <table class="form">
                <tr>
                    <th class="formTitle">申请单时间范围：</th>
                    <td class="formValue" colspan="2">
                        <input id="jy_kssj" type="text" class="form-control input-wdatepicker" style="width:30%;  float:left;" value="@DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        <span style="margin-left:1%;float:left">—</span>
                        <input id="jy_jssj" type="text" class="form-control input-wdatepicker" style="width:30%; float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                    </td>
                    <th class="formTitle">组套名称：</th>
                    <td class="formValue">
                        <input id="jy_ztmc" type="text" class="form-control" placeholder="组套名称" />
                    </td>
                    <td class="formValue">
                        &nbsp;&nbsp;
                        <input type="button" id="btn_jysearch" class="btn btn-primary" value=" 查 询 " />
                        @*<a href="~/File/CQLisApp.rar">CQLisApp</a>*@
                    </td>
                </tr>
            </table>
        </div>
        <div class="gridPanel">
            <table id="jyGridList"></table>
            <div id="jyGridPager" style="padding-right:20%"></div>
            <div id="tsjy" style="color:blue">请双击一条已完成的数据来查看明细</div>
        </div>
        <div id="jydc" style="height:50px" class="hide">
            <input type="checkbox" id="gxyc" name="gxyc" style="float:left" onclick="gxycclick(this)"  />异常结果勾选
            <input type="button" id="jgdc" name="jgdc" class="btn btn-md btn-primary" style="float:right;  margin-right:100px;" value="结果导入" class="noselected" />
            <input type="button" id="xmjgdc" name="xmjgdc" class="btn btn-md btn-primary" style="float:right; margin-right:60px;" value="项目+结果导入" class="noselected" />
        </div>
        <div class="gridPanel">
            <table id="jyMxGridList"></table>
        </div>
    </div>
    <div class="panel panel-default hide" id="jcjgmx">
        <div>
            <table class="form">
                <tr>
                    <th class="formTitle">申请单时间范围：</th>
                    <td class="formValue" colspan="2">
                        <input id="jc_kssj" type="text" class="form-control input-wdatepicker" style="width:30%;  float:left;" value="@DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        <span style="margin-left:1%;float:left">—</span>
                        <input id="jc_jssj" type="text" class="form-control input-wdatepicker" style="width:30%; float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                    </td>
                    <th class="formTitle">组套名称：</th>
                    <td class="formValue">
                        <input id="jc_ztmc" type="text" class="form-control" placeholder="组套名称" />
                    </td>
                    <td class="formTitle">
                        <input type="button" id="btn_jcsearch" class="btn btn-md btn-primary" value="查询" />
                    </td>

                </tr>
            </table>
        </div>
        <div class="gridPanel">
            <table id="jcGridList" rel="formPatSer"></table>
            <div id="jcGridPager" style="padding-right:20%"></div>
            <div id="tsjc" style="color:blue">请双击一条已完成的数据来查看明细</div>
        </div>
		<div style="height:50px">
			<input id="dc" class="btn btn-md btn-primary" name="dc" type="button" style="float:right; width:100px;  margin-right:100px;" value="导入" />
			
		</div>
		<div id="jcjgdiv">
			<label style="">文字报告：</label>
			<textarea name="" cols="15" rows="4" id="jcjgtext" readonly style="width:95%;height:100px; border:none; resize:none"></textarea>
		</div>
        <div class="gridPanel">
            <table id="jcMxGridList"></table>
        </div>
    </div>
    @*onclick="document.getElementById('myWriterControl').DCExecuteCommand('Spechars', true, 'test');"*@
</form>

<script lang="javascript">
    var mzzyh = $.request("mzzyh");
    var type = $.request("type");
	var jyzt;
	var jlxx = null;//记录tab选中的
	$('#myTab a:first').trigger('click'); //初始化显示哪个tab
    $(function () {
		jyGridList();
		jlxx = $('#myTab a:first').attr('href');
		console.log("初始化：", jlxx);
    })
    //$(document).ready(function () {
    //    $("#btn_jcsearch").trigger('click');
    //});
    $("#btn_jcsearch").click(function () {
        var kssj = $('#jc_kssj').val();
        var jssj = $('#jc_jssj').val() + " 23:59:59";
        var ztmc = $('#jc_ztmc').val();
        $("#jcGridList").jqGrid('setGridParam', {
            postData: { mzzyh: mzzyh, type: type, ztmc: ztmc, kssj: kssj, jssj: jssj },
        }).trigger('reloadGrid'); //重新加载当前表格
    });

    $('#btn_jysearch').click(function () {
        var kssj = $('#jy_kssj').val();
        var jssj = $('#jy_jssj').val() + " 23:59:59";
        var ztmc = $('#jy_ztmc').val();
        $("#jyGridList").jqGrid('setGridParam', {
            postData: { mzzyh: mzzyh, type: type, ztmc: ztmc, kssj: kssj, jssj: jssj },
        }).trigger('reloadGrid'); //重新加载当前表格
    });

    function jyGridList() {
        var kssj = $('#jy_kssj').val();
        var jssj = $('#jy_jssj').val() + " 23:59:59";
        var ztmc = $('#jy_ztmc').val();
        var $jyGridList = $("#jyGridList");
        $jyGridList.dataGrid({
            url: "/MedicalRecord/GetLisSqdhGridJson",
            autowidth: false,
            postData: { mzzyh: mzzyh, type: type, ztmc: ztmc, kssj: kssj, jssj: jssj },
            width: $("#formPatSer").width() - 10,
            //height: $(window).height() - 170,
            height: 125,
            colModel: [
                { label: '姓名', name: 'xm', align: 'center', hidden: true },
                { label: '申请单号', name: 'lissqdh', align: 'center', width: '160px' },
                { label: '组套名称', name: 'ztmc', align: 'center', width: '170px' },
                { label: '申请时间', name: 'sqsj', align: 'center', width: '160px' },
                { label: '申请单状态', name: 'syncStatus', align: 'center', width: '160px' },
                {
                    label: "操作", name: "", align: "center", width: '150',
                    formatter: function (cellvalue, options, rowobject) {
                        return "<a href=\#\" onclick='jyrecall1(\"" + rowobject.lissqdh + "\",\"" + rowobject.syncStatus + "\")'' title='lis报告' style='text-decoration: none;color: #dd4b39;cursor: pointer;'>查看报告</a>";
                    }
                }
            ],
            pager: "#jyGridPager",
            sortname: 'sqsj desc',
            viewrecords: true
        });
    }

    function jcGridList() {
        var kssj = $('#jc_kssj').val();
        var jssj = $('#jc_jssj').val() + " 23:59:59";
        var ztmc = $('#jc_ztmc').val();
        var $jcGridList = $("#jcGridList");
        $jcGridList.dataGrid({
            url: "/MedicalRecord/GetPacsSqdhGridJson",
            autowidth: false,
            postData: { mzzyh: mzzyh, type: type, ztmc: ztmc, kssj: kssj, jssj: jssj },
            width: $(window).width() - 10,
            //height: $(window).height() - 170,
            height: 175,
            colModel: [
                { label: '姓名', name: 'xm', align: 'center', hidden: true },
                { label: '申请单号', name: 'lissqdh', align: 'center', width: '160px' },
                { label: '组套名称', name: 'ztmc', align: 'center', width: '170px' },
                { label: '申请时间', name: 'sqsj', align: 'center', width: '160px' },
                { label: '申请单状态', name: 'syncStatus', align: 'center', width: '160px' },
                {
                    label: "操作", name: "", align: "center", width: '150',
                    formatter: function (cellvalue, options, rowobject) {
                        return "<a href=\#\" onclick='jcrecall1(\"" + rowobject.lissqdh + "\",\"" + rowobject.syncStatus + "\")'' title='查看报告' style='text-decoration: none;color: #dd4b39;cursor: pointer;'>查看报告</a>";
                    }
                }
            ],
            pager: "#jcGridPager",
            sortname: 'sqsj desc',
            viewrecords: true
        });
    }

    function jcrecall1(sqdh, syncStatus) {
        if (syncStatus != "已完成") {
            $.modalAlert("当前状态不是已完成状态不能查看报告", 'warning');
            return;
        }
        else {
            //$.modalOpen({
            //    id: "medicaljgForm",
            //    title: "检查报告",
            //    url: "http://116.63.189.68:8088/WebSearch.aspx?ReqNO='" + sqdh + "'",
            //    width: "1000px",
            //    height: "1000px",
            //    btn: ['', ''],
            //    btnclass: ['', ''],
            //});
			window.open('https://pacs.jidachengdu.com:18000/externalView?hosCode=jdkfyy&studyNum=' + sqdh);
        }

    }

    function jyrecall1(lissqdh, syncStatus) {
        if (syncStatus != "已完成") {
            $.modalAlert("当前状态不是已完成状态不能查看报告", 'warning');
            return;
        } else {
            $.ajax({
                url: "http://127.0.0.1:22228/api/CQSmartCheck/GetLisReport",//lis报告
                dataType: "json",
                data: { type: type, brxx_id: lissqdh },
                type: "POST",
                async: true,
                success: function (ajaxdata) { }
            });
        }
    }

    //jqGrid 双击选中某行
	function btn_edit() {

		if (jlxx == "#jy") {
            var $jyGridList = $("#jyGridList");
            if ($jyGridList.jqGridRowValue().syncStatus != "已完成") {
                $.modalAlert("当前状态不是已完成状态不能查看报告", 'warning');
                return;
            }
            else {
                var $mxgridList = $("#jyMxGridList");
                $("#gxyc").checked = false;
				$("#jydc").removeClass("hide");
				$("#tsjy").addClass("hide");
                jyzt = $jyGridList.jqGridRowValue().ztmc;
                $mxgridList.dataGrid({
                    url: "/MedicalRecord/GetLisSqdhMxGridJson",
                    //autowidth: false,
                    postData: { zyh: mzzyh, lissqdh: $jyGridList.jqGridRowValue().lissqdh },
                    //width: $(window).width() - 10,
                    height: 120,
                    colModel: [
                        { label: '项目名称', name: 'xmmc', align: 'left', width: '180px' },
                        { label: '检验结果', name: 'jyjg', align: 'left', width: '180px' },
                        { label: '高低标记', name: 'gdbj', align: 'left', width: '100px' },
                        { label: '参考值范围', name: 'ckzfw', align: 'left', width: '120px' },
                        { label: '单位', name: 'dw', align: 'left', width: '180px' }
                    ],
                    sortname: 'sqsj desc',
                    viewrecords: true,
                    multiselect: true
                });
                $("#jyMxGridList").jqGrid('setGridParam', {
                    postData: { zyh: mzzyh, lissqdh: $jyGridList.jqGridRowValue().lissqdh },
                }).trigger('reloadGrid');
            }
        }
        else {
            var $jcGridList = $("#jcGridList");
            if ($jcGridList.jqGridRowValue().syncStatus != "已完成") {
                $.modalAlert("当前状态不是已完成状态不能查看报告", 'warning');
                return;
            }
            else {
				$("#dc").removeClass("hide");
				$("#jcjgdiv").removeClass("hide");
				$("#tsjc").addClass("hide");
				//var $mxgridList = $("#jcMxGridList");
				$.ajax({
					url: "/MedicalRecord/GetPacsSqdhMxGridJson",
					dataType: "json",
					data: { sqdh: $jcGridList.jqGridRowValue().lissqdh },
					type: "POST",
					async: false,
					success: function (result) {
						console.log("申请单号查询检查结果：", result);
						var strjcjg="";
						if (result.length > 0) {
							for (var i = 0; i < result.length; i++) {
								strjcjg += "" + result[i].jcjg+"";
							}
							$("#jcjgtext").val(strjcjg);
						}
					}
				});
                //$mxgridList.dataGrid({
                //    url: "/MedicalRecord/GetPacsSqdhMxGridJson",
                //    //autowidth: false,
                //    postData: { sqdh: $jcGridList.jqGridRowValue().lissqdh },
                //    //width: $(window).width() - 10,
                //    height: 175,
                //    colModel: [
                //        { label: '检查结果', name: 'jcjg', align: 'left', width: '840px' },
                //    ],
                //    sortname: 'sqsj desc',
                //    viewrecords: true,
                //});
                //$("#jcMxGridList").jqGrid('setGridParam', {
                //    postData: { sqdh: $jcGridList.jqGridRowValue().lissqdh },
                //}).trigger('reloadGrid');
            }
        }

    }

    function gxycclick(checkbox) {
        if (checkbox.checked == true) {
            debugger
            var rowIds = jQuery("#jyMxGridList").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var curRowData = jQuery("#jyMxGridList").jqGrid('getRowData', rowIds[k]);
                if (curRowData.gdbj != null && curRowData.gdbj != "") {
                    //$("#" + rowIds[k] + "").attr("aria-selected", "true");
                    //$("#" + rowIds[k] + "").addClass("success");
                    //var curChk = $("#" + rowIds[k] + "").find(":checkbox");
                    $("#" + rowIds[k], "#jyMxGridList").attr("aria-selected", "true");
                    $("#" + rowIds[k], "#jyMxGridList").addClass("success");
                    var curChk = $("#" + rowIds[k], "#jyMxGridList").find(":checkbox");
                    curChk.attr("checked", "true");
                };
            };
        }
        else {
            $("#jyMxGridList").trigger("reloadGrid");
        }
    };

    function getids() {
        debugger
        var rowIds = jQuery("#jyMxGridList").jqGrid('getDataIDs');
        var ids = new Array();
        for (var k = 0; k < rowIds.length; k++) {
            if ($("#" + rowIds[k], "#jyMxGridList").hasClass("success")) {
                ids.push(k);
            }
        }
        return ids;
    }


	$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
		
		jlxx = $(this).attr('href');
		console.log("TAB：", jlxx);
		transferPage($(this).attr('href'));

	});
	 function transferPage($thishref) {
		 switch ($thishref) {
			 case "#jy":
				 $("#jcjgmx").addClass("hide");
				 $("#jyjgmx").removeClass("hide");
				 $("#jc").addClass("noselected");
				 $("#jc").removeClass("selected");
				 $("#jy").addClass("selected");
				 $("#jy").removeClass("noselected");

				 //$("#dc").addClass("hide");
				 $(function () {
					 jyGridList();

				 });
				 //$("#jyMxGridList").clearGridData();
                 //$("#jcMxGridList").dataGrid.width = 690
				 break;
			 case "#jc":
				 $("#jyjgmx").addClass("hide");
				 $("#jcjgmx").removeClass("hide");
				 $("#jc").addClass("selected");
				 $("#jc").removeClass("noselected");
				 $("#jy").addClass("noselected");
				 $("#jy").removeClass("selected");

				 $("#dc").addClass("hide");
				 $("#jcjgdiv").addClass("hide");
				 $(function () {
					 jcGridList();
				 });
				 //$("#jcMxGridList").clearGridData();
                 //$("#jcMxGridList").dataGrid.width=690
				 break;
		 }
    }


	$("#dc").click(function () {
		if ($("#jcjgtext").val() != undefined && $("#jcjgtext").val() != null && $("#jcjgtext").val()!="") {
			console.log("检查结果",$("#jcjgtext").val());
			$.currentWindow().document.getElementById('myWriterControl').DCExecuteCommand('Spechars', true, $("#jcjgtext").val());
		} else {
			$.modalAlert("该申请单号无检查结果显示无法导入内容", 'warning');
			return;
		}
		
    });

    $("#jgdc").click(function () {
        //rowIds = $('#jyMxGridList').jqGrid('getGridParam', 'selarrrow');
        rowIds = getids();
        if (rowIds.length < 1) {
			//alert("请至少选择一行检验结果导出！");
			$.modalAlert("请至少选择一行检验结果导出！", 'warning');
        }
        else {
            var jg = "";
            for (var k = 0; k < rowIds.length; k++) {
                var rowData = $("#jyMxGridList").jqGrid('getRowData', rowIds[k]+1);
                jg += (rowData.xmmc == undefined ? " " : rowData.xmmc) + " " + (rowData.jyjg == undefined ? " " : rowData.jyjg) + (rowData.gdjg == undefined ? " " : rowData.gdjg) + (rowData.dw == undefined ? " " : rowData.dw) + "，";
            };
            $.currentWindow().document.getElementById('myWriterControl').DCExecuteCommand('Spechars', true, jg);
        };
    });

    $("#xmjgdc").click(function () {
        //rowIds = $('#jyMxGridList').jqGrid('getGridParam', 'selarrrow');
        rowIds = getids();
        if (rowIds.length < 1) {
			//alert("请至少选择一行检验结果导出！");
			$.modalAlert("请至少选择一行检验结果导出！", 'warning');
        }
        else {
            var jg = jyzt;
            for (var k = 0; k < rowIds.length; k++) {
                var rowData = $("#jyMxGridList").jqGrid('getRowData', rowIds[k]+1);
                jg += "： " + (rowData.xmmc == undefined ? " " : rowData.xmmc) + " " + (rowData.jyjg == undefined ? " " : rowData.jyjg) + (rowData.gdjg == undefined ? " " : rowData.gdjg) + (rowData.dw == undefined ? " " : rowData.dw) + "，";
            };
            $.currentWindow().document.getElementById('myWriterControl').DCExecuteCommand('Spechars', true, jg);
        };
    })
    //var btn_dc = document.querySelector("#dc");
    //btn_dc.onmousedown = function(event) {event.preventDefault()}
</script>
